{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "# Ch `04`: Concept `04` "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Softmax classification"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Import the usual libraries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import numpy as np\n",
    "import tensorflow as tf\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Generated some initial 2D data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAEACAYAAACnJV25AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnX2UVNWZ7p9d3XQ1VdqNBoEgYqNiBATabvBqlOlCMbhC\nTBPvYgbBKxln0on0REfuMjoyK1WtdhCT0Dpzyazl1bDsD8MIRuQOgSTELiMzOupNFCeaCIkETSa6\n5iNzVxrB/njvH1W7OHX6nDrnVJ36Ov381qoFVXXOPvsU+uz3PPvd71YiAkIIIcEhVO4OEEII8RcK\nOyGEBAwKOyGEBAwKOyGEBAwKOyGEBAwKOyGEBAxfhF0pdadS6l+UUoeVUgNKqTo/2iWEEOKdgoVd\nKTUTwJcBtIjIIgC1ANYW2i4hhJD8qPWpnRoAUaXUGIAIgN/61C4hhBCPFByxi8hvAXwTwHEAvwHw\nexE5WGi7hBBC8sMPK2YKgHYA5wOYCeAMpdS6QtslhBCSH35YMSsA/EpE/gMAlFLfB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x56hUR\nuc7q8/SCpiYAryul9IKm/6uUslzQVGzs+qlRSn0eqUf0a0rSIXf8BsBsw3u9KKziSD+K7wbQJyLP\nlrs/NlwF4LNKqU8DmAzgTKVUr4jcUuZ+mXkPqSfdV9PvdwOoxInzFQB+JSL/AQBKqe8C+CSASg2M\n3ldKTReR95VSMwCUXIfc4lWPSmbFiMi/iMgMEblAROYg9R/rZeUQdSeUUtcj9Xj+WRE5Ve7+GHgF\nwEVKqfPT2QZrAVRqJse3AbwpIo+UuyN2iMi9IjJbRC5A6rd8rgJFHWm74F2l1MXpj65FZU72Hgdw\nhVKqPh28XYvKmuQ1P5XtBfD59N83AKiUACSrn/noke8RuwcqeUHT3wKoA/DD1H+feElENpa3S4CI\njCql/gKpWfIQgMdFpJL+xwEAKKWuArAewBtKqZ8i9W99r4gcKG/PqprbAQwopSYB+BWAPy1zf8Yh\nIi8rpXYD+CmA4fSfj5a3VymUUk8CiAH4mFLqOFKW8IMAdimlbkUqS++Py9fDFDb9vBce9YgLlAgh\nJGBwazxCCAkYFHZCCAkYFHZCCAkYFHZCCAkYFHZCCAkYFHZCCAkYFHZCCAkYFHZCCAkY/x/9qPoP\nmjF9JgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f80cce46e10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "learning_rate = 0.01\n",
    "training_epochs = 1000\n",
    "num_labels = 3\n",
    "batch_size = 100\n",
    "\n",
    "x1_label0 = np.random.normal(1, 1, (100, 1))\n",
    "x2_label0 = np.random.normal(1, 1, (100, 1))\n",
    "x1_label1 = np.random.normal(5, 1, (100, 1))\n",
    "x2_label1 = np.random.normal(4, 1, (100, 1))\n",
    "x1_label2 = np.random.normal(8, 1, (100, 1))\n",
    "x2_label2 = np.random.normal(0, 1, (100, 1))\n",
    "\n",
    "plt.scatter(x1_label0, x2_label0, c='r', marker='o', s=60)\n",
    "plt.scatter(x1_label1, x2_label1, c='g', marker='x', s=60)\n",
    "plt.scatter(x1_label2, x2_label2, c='b', marker='_', s=60)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Define the labels and shuffle the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "xs_label0 = np.hstack((x1_label0, x2_label0))\n",
    "xs_label1 = np.hstack((x1_label1, x2_label1))\n",
    "xs_label2 = np.hstack((x1_label2, x2_label2))\n",
    "\n",
    "xs = np.vstack((xs_label0, xs_label1, xs_label2))\n",
    "labels = np.matrix([[1., 0., 0.]] * len(x1_label0) + [[0., 1., 0.]] * len(x1_label1) + [[0., 0., 1.]] * len(x1_label2))\n",
    "\n",
    "arr = np.arange(xs.shape[0])\n",
    "np.random.shuffle(arr)\n",
    "xs = xs[arr, :]\n",
    "labels = labels[arr, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "We'll get back to this later, but the following are test inputs that we'll use to evaluate the model:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "test_x1_label0 = np.random.normal(1, 1, (10, 1))\n",
    "test_x2_label0 = np.random.normal(1, 1, (10, 1))\n",
    "test_x1_label1 = np.random.normal(5, 1, (10, 1))\n",
    "test_x2_label1 = np.random.normal(4, 1, (10, 1))\n",
    "test_x1_label2 = np.random.normal(8, 1, (10, 1))\n",
    "test_x2_label2 = np.random.normal(0, 1, (10, 1))\n",
    "test_xs_label0 = np.hstack((test_x1_label0, test_x2_label0))\n",
    "test_xs_label1 = np.hstack((test_x1_label1, test_x2_label1))\n",
    "test_xs_label2 = np.hstack((test_x1_label2, test_x2_label2))\n",
    "\n",
    "test_xs = np.vstack((test_xs_label0, test_xs_label1, test_xs_label2))\n",
    "test_labels = np.matrix([[1., 0., 0.]] * 10 + [[0., 1., 0.]] * 10 + [[0., 0., 1.]] * 10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Again, define the placeholders, variables, model, and cost function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "train_size, num_features = xs.shape\n",
    "\n",
    "X = tf.placeholder(\"float\", shape=[None, num_features])\n",
    "Y = tf.placeholder(\"float\", shape=[None, num_labels])\n",
    "\n",
    "W = tf.Variable(tf.zeros([num_features, num_labels]))\n",
    "b = tf.Variable(tf.zeros([num_labels]))\n",
    "y_model = tf.nn.softmax(tf.matmul(X, W) + b)\n",
    "\n",
    "cost = -tf.reduce_sum(Y * tf.log(y_model))\n",
    "train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)\n",
    "\n",
    "correct_prediction = tf.equal(tf.argmax(y_model, 1), tf.argmax(Y, 1))\n",
    "accuracy = tf.reduce_mean(tf.cast(correct_prediction, \"float\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Train the softmax classification model:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 109.861\n",
      "100 11.1746\n",
      "200 7.66511\n",
      "300 6.14837\n",
      "400 7.36667\n",
      "500 6.21197\n",
      "600 5.20238\n",
      "700 6.67839\n",
      "800 5.75361\n",
      "900 4.70638\n",
      "1000 6.39738\n",
      "1100 5.49439\n",
      "1200 4.38705\n",
      "1300 6.25161\n",
      "1400 5.32159\n",
      "1500 4.16287\n",
      "1600 6.16709\n",
      "1700 5.19838\n",
      "1800 3.9968\n",
      "1900 6.11495\n",
      "2000 5.10726\n",
      "2100 3.8689\n",
      "2200 6.08159\n",
      "2300 5.03829\n",
      "2400 3.76737\n",
      "2500 6.05979\n",
      "2600 4.98517\n",
      "2700 3.68479\n",
      "2800 6.04543\n",
      "2900 4.94369\n",
      "w [[-2.54555464  0.36140779  2.18415737]\n",
      " [-0.09027337  1.47717059 -1.38689983]]\n",
      "b [ 10.06975937  -2.41784143  -7.65189791]\n",
      "accuracy 0.966667\n"
     ]
    }
   ],
   "source": [
    "with tf.Session() as sess:\n",
    "    tf.global_variables_initializer().run()\n",
    "\n",
    "    for step in range(training_epochs * train_size // batch_size):\n",
    "        offset = (step * batch_size) % train_size\n",
    "        batch_xs = xs[offset:(offset + batch_size), :]\n",
    "        batch_labels = labels[offset:(offset + batch_size)]\n",
    "        err, _ = sess.run([cost, train_op], feed_dict={X: batch_xs, Y: batch_labels})\n",
    "        if step % 100 == 0:\n",
    "            print (step, err)\n",
    "\n",
    "    W_val = sess.run(W)\n",
    "    print('w', W_val)\n",
    "    b_val = sess.run(b)\n",
    "    print('b', b_val)\n",
    "    print(\"accuracy\", accuracy.eval(feed_dict={X: test_xs, Y: test_labels}))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
